extends Node2D

var time = 45
var final_result = 0
var score = 0

func _ready():
	randomize()
	text()
	pass

func text():
	var array = []
	for i in 4:
		array.append(gen())
	var index = 0
	for element in array:
		final_result += element
		$VBoxContainer.get_child(index).text = str(array[index])  + "元"
		index +=1
	print(final_result)
	
func gen():
	var rand = rand_range(0,100)
	return stepify(rand, 0.01) 
	pass
	
func _on_Timer_timeout():
	time -= 1
	$Time.text = "Time:" + str(time)
	if time <=0:
		get_tree().change_scene("res://End.tscn")
	pass # Replace with function body.


func _on_Ok_pressed():
	var c = float($LineEdit.text)
	if abs(c -final_result)< 0.001:
		text()
		score +=5
		Global.score = score
		$Score.text = "积分:" + str(score)
		time+=175
	else:
		time-=75
	pass # Replace with function body.
